﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _111_对象池
{
    class EntiyPool
    {
        public static Stack<Entity> pools = new Stack<Entity>();

        public static T ShowEntity<T>(EntityData data) where T: Entity
        {
            if (pools.Count < 1)
            {
                Entity entity = (T)Activator.CreateInstance(typeof(T), new object[] { data });
                pools.Push(entity);
                Console.WriteLine("{0}显示成功！！", entity.Name);
                return pools.Pop() as T;
            }
            Console.WriteLine("{0}显示成功！！", pools.Peek().Name);
            return pools.Pop() as T;
        }

    }
}
